<?php
namespace Index\Controller;
use Think\Controller;
class QuestionController extends Controller {
    public function indexAction(){

    	$get = I('get.id');
    	$Model = M();
    	$question = $Model->query("SELECT * FROM question where id='{$get}'");
    	if (empty($question)) {
    		$this->error('用户不存在',$_SERVER['HTTP_REFERER'],2);
    	}
    	$question = $question[0];
		var_dump($question);
    	$question['content']= htmlspecialchars_decode($question['content']);//把标签实体化

		$sql3 = "select * from question WHERE cid='$question[cid]'";
		$questions = $Model->query($sql3);
//		var_dump($questions);
		$this->assign('questions',$questions);


    	$this->assign('question',$question);

		$sql1 = "select t2.username,t2.face_url,t2.introduce from question t1 inner join user t2 on t1.uid=t2.id and t1.id ='{$get}'";
		$user = $Model->query($sql1);
//		var_dump($user);
		$user = $user[0];
		$this->assign('user',$user);
		$sql2 = "select t2.face_url,t1.content from answer t1 left join user t2 on t1.uid=t2.id WHERE t1.qid='{$get}'";
		$reply = $Model->query($sql2);
//		var_dump($reply);
		$this->assign('reply',$reply);




    	$this->display('index');



    }
//回复 回答
	public function questionAction(){
		$uid = $_SESSION['uid'];
		$qid = I('post.id');
		$textarea = I('post.textarea');
//		var_dump($uid);
//		var_dump($qid);
//		var_dump($textarea);

		$Model = M();


		$sql = "insert into `answer` (uid,qid,content) VALUES('{$uid}','{$qid}','{$textarea}')";

		if($Model->execute($sql)){
			$this->success('回复成功','',2);
		} ;

	}

}